/**************************************************************************//**
 * @file     iic_soft.h
 * @brief    Software IIC Header File
 * @version  V1.00
 * @date     25. March 2017
 *
 * @note
 *
 ******************************************************************************/

#ifndef __IIC_SOFT_H__
#define __IIC_SOFT_H__


/********************************************************************************
 * Include section
 *******************************************************************************/
//#include "Gpio.h"
#include <stdint.h>
#include "BSP_gpio.h"

/********************************************************************************
 * Typedefs, structs and enums
 *******************************************************************************/

 
/********************************************************************************
 * Constants and macros
 *******************************************************************************/
#define  SDA_OUT_EN  GPIO_OutputEnable (GPIO_IIC_SDA)
#define  SDA_OUT_DIS GPIO_OutputDisable(GPIO_IIC_SDA)

#define  AT24C01   1
#define  AT24C02   2
#define  AT24C04   4
#define  AT24C08   8
#define  AT24C016  16

#define  EEPROM_CHIP  AT24C02


#if (EEPROM_CHIP == AT24C01)
  #define   PAGE_NUMB   (8)
#elif (EEPROM_CHIP == AT24C02)
  #define   PAGE_NUMB   (16)
#elif (EEPROM_CHIP == AT24C04)
  #define   PAGE_NUMB   (16)
#elif (EEPROM_CHIP == AT24C08)
  #define   PAGE_NUMB   (16)
#elif (EEPROM_CHIP == AT24C016)
  #define   PAGE_NUMB   (16)
#else
  #error no EEPROM defined
#endif   

#define WRITE_BYTE_DELAY 0x0000A000UL  // 0x9000@72MHz
#define WRITE_PAGE_DELAY (WRITE_BYTE_DELAY*PAGE_NUMB)

/********************************************************************************
 * Variables
 *******************************************************************************/

 /********************************************************************************
 * prototypes of the functions
 *******************************************************************************/
extern uint8_t IIC_ReadByte(uint8_t address);
extern void IIC_WriteByte(uint8_t address, uint8_t  info);
extern void IIC_WritePage(uint8_t * pBuff, uint16_t u16Cnt, uint16_t u16BaseAdd);
extern void IIC_ReadPage (uint8_t * pBuff, uint16_t u16Cnt, uint16_t u16BaseAdd);
extern void IIC_test(void);

/*---------------------------------- End of the file ---------------------------------*/
#endif /* __IIC_SOFT_H__ */

